import webapp2
from webapp2_extras.i18n import gettext as _

from google.appengine.api import users
from common import functions
from apnetmodels.basicmodels import immeuble 
from BaseHandler import BaseHandler

class MainPage(BaseHandler):
    def get(self):
        au = functions.GetAPNETUser()
        if not au:
            self.redirect(webapp2.uri_for('registration', command="user"))
            return
        
        imm = immeuble.get_by_id(au.last_active_immeuble_id)
        
        content = unicode(au) + ": " + unicode(au.key().name())
        
        h = _("Welcome!")
        title = _("Real estate management application")
        header = _("ATENET. Real estate management application")
        template_values = {
                'title': title,
                'header': header,
                'content_header': h,
                'main_content': content,
                'app_user': au,
                'immeuble': imm,
                'lurl': users.create_logout_url('/')
            }
        
#        self.render_template('templates/main_page.html', name=self.request.get('name'))
        template = self.jinja2.get_template('templates/main_page.html')
        self.response.out.write(template.render(template_values))
